#!/usr/bin/env python

# The clipping plane: an extra-reality dimension that forms the 4th wall
# when you are moving from the perspective of the character inside the game

from pandac.PandaModules import MovieTexture
from direct.gui.OnscreenText import OnscreenText

# --------------------------
def initClippingPlane(self):
# --------------------------
    # Clipping plane variables
    self.X_OFF = 2 
    self.Y_OFF = 0 
    self.Z_OFF = 6
 
    self.CPYAW = 0 
    self.CPPITCH = 0 
    self.CPROLL = 0 

    self.VIDYAW = 0 
    self.VIDPITCH = 0 
    self.VIDROLL = 0 

    self.CP_SX = 10
    self.CP_SY = 20
    self.CP_SZ = 16

    self.clip_plane = loader.loadModel("../models/clipping-plane/clipping_plane.egg")
    self.clip_plane.reparentTo(render)
    self.clip_plane.setPos(self.ralph.getX() + self.X_OFF, self.ralph.getY() + self.Y_OFF, self.ralph.getZ() + self.Z_OFF)
    self.clip_plane.setHpr(self.CPYAW, self.CPPITCH, self.CPROLL)
    self.clip_plane.setScale(self.CP_SX, self.CP_SY, self.CP_SZ)

    self.tex0 = MovieTexture("movie0")
    assert self.tex0.read("../models/videos/loop_new.avi"), "Video 0 FAIL"
    self.tex1 = MovieTexture("movie1")
    assert self.tex1.read("../models/videos/distraction1_new.avi"), "Video 1 FAIL"
    self.tex2 = MovieTexture("movie2")
    assert self.tex2.read("../models/videos/distraction2_new.avi"), "Video 2 FAIL"
    self.tex3 = MovieTexture("movie3")
    assert self.tex3.read("../models/videos/distraction3_new.avi"), "Video 3 FAIL"
     
    self.vid = loader.loadModel("../models/clipping-plane/video_screen.egg")
    self.vid.reparentTo(render)
    self.vid.setTexture(self.tex0, 1)
    self.currentTex = self.tex0
    self.vid.setPos(self.ralph.getX() + self.X_OFF, self.ralph.getY() + self.Y_OFF, self.ralph.getZ() + self.Z_OFF)
    self.vid.setHpr(self.VIDYAW, self.VIDPITCH, self.VIDROLL)
    self.vid.setScale(self.CP_SX, self.CP_SY, self.CP_SZ)
    
# --------------------------
def moveClippingPlane(self):
# --------------------------
    self.clip_plane.setY(self.ralph.getY() + self.Y_OFF)
    self.vid.setY(self.ralph.getY() + self.Y_OFF)

# ----------------------------
def changeVideo(self, vidNum):
# ----------------------------
    self.currentTex.stop()
    if vidNum == 0:
        self.vid.setTexture(self.tex0, 1)
        self.currentTex = self.tex0
        self.currentTex.play()
    elif vidNum == 1:
        self.vid.setTexture(self.tex1, 1)
        self.currentTex = self.tex1
        self.currentTex.play()
    elif vidNum == 2:
        self.vid.setTexture(self.tex2, 1)
        self.currentTex = self.tex2
        self.currentTex.play()
    elif vidNum == 3:
        self.vid.setTexture(self.tex3, 1)
        self.currentTex = self.tex3
        self.currentTex.play()

